package controle;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Vector;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.beanutils.BeanUtils;

import smile.Network;

import modelo.Atividade;
import modelo.Normal;



import dataBase.AtividadeBD;
import dataBase.NormalBD;


public class BNList extends HttpServlet {
    public void init(ServletConfig config) throws ServletException {
	super.init(config);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	executeServlet(request, response);
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	executeServlet(request, response);
    }

    public void executeServlet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	response.setContentType("text/html");
	HttpSession session = request.getSession(true);



	    Vector redesBassianas = new Vector();
	    Vector nodos = new Vector();
	   
		File dir = new File("C:\\teste\\");

		FilenameFilter filter = new FilenameFilter() {
			public boolean accept(File dir, String name) {
				return name.endsWith(".xdsl");
			}
		};

		String[] children = dir.list(filter);
		for (int i = 0; i < children.length; i++) {
			// Get filename of file or directory
			redesBassianas.add(children[i]);
	
		}
		
	    int event = 0;
	    

	    try {
		event = Integer.parseInt(request.getParameter("event"));
	    } catch (Exception e) {
		event = 1;
	    }
	    String selecionado=request.getParameter("ListBn");	

	    switch (event) {
	    case 2:	Network net = new Network();
	    		
	    	net.readFile("c://teste//"+selecionado);
	    		
	    		String[] temp=net.getAllNodeIds();
	    		for (int i = 0; i < temp.length; i++) {
	    			nodos.add(temp[i]);

				}
	    		

	    }

	    request.setAttribute("BNS", redesBassianas);
	    request.setAttribute("nodos", nodos);
	    request.setAttribute("selecionado", selecionado);
	    getServletContext().getRequestDispatcher("/BNList.jsp").forward(request, response);
	    
	

    }

}
